package com.ruoyi.aproduct.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.aproduct.domain.ShProduct;
import com.ruoyi.aproduct.service.IShProductService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文物产品管理Controller
 * 
 * @author ruoyi
 * @date 2021-12-29
 */
@Controller
@RequestMapping("/shaproduct/aproduct")
public class ShProductController extends BaseController
{
    private String prefix = "shaproduct/aproduct";

    @Autowired
    private IShProductService shProductService;

    @RequiresPermissions("shaproduct:aproduct:view")
    @GetMapping()
    public String aproduct()
    {
        return prefix + "/aproduct";
    }

    /**
     * 查询文物产品管理列表
     */
    @RequiresPermissions("shaproduct:aproduct:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShProduct shProduct)
    {
        startPage();
        List<ShProduct> list = shProductService.selectShProductList(shProduct);
        return getDataTable(list);
    }

    /**
     * 导出文物产品管理列表
     */
    @RequiresPermissions("shaproduct:aproduct:export")
    @Log(title = "文物产品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShProduct shProduct)
    {
        List<ShProduct> list = shProductService.selectShProductList(shProduct);
        ExcelUtil<ShProduct> util = new ExcelUtil<ShProduct>(ShProduct.class);
        return util.exportExcel(list, "文物产品管理数据");
    }

    /**
     * 新增文物产品管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文物产品管理
     */
    @RequiresPermissions("shaproduct:aproduct:add")
    @Log(title = "文物产品管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShProduct shProduct)
    {
        return toAjax(shProductService.insertShProduct(shProduct));
    }

    /**
     * 修改文物产品管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShProduct shProduct = shProductService.selectShProductById(id);
        mmap.put("shProduct", shProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存文物产品管理
     */
    @RequiresPermissions("shaproduct:aproduct:edit")
    @Log(title = "文物产品管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShProduct shProduct)
    {
        return toAjax(shProductService.updateShProduct(shProduct));
    }

    /**
     * 删除文物产品管理
     */
    @RequiresPermissions("shaproduct:aproduct:remove")
    @Log(title = "文物产品管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shProductService.deleteShProductByIds(ids));
    }
}
